/**
 * 账户设置界面
 * @author William
 * 2012-5-10
 */
package com.ytu.clouddisk.face;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class CloudDiskLoginActivity extends Activity {

	private Button btnGoogle;
	private Button btnKanBox;
	private Button btnSnda;
	private Button btnVDisk;
	private Button btnKuaiPan;

	private Button btnOK;
	private Button btnExit;

	private OnClickListener listenerBtn;
	private SharedPreferences sp;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();

	}

	protected void init() {
		btnGoogle = (Button) findViewById(R.id.btn_google_account);
		btnKanBox = (Button) findViewById(R.id.btn_kanbox_account);
		btnSnda = (Button) findViewById(R.id.btn_snda_account);
		btnVDisk = (Button) findViewById(R.id.btn_vdisk_account);
		btnKuaiPan = (Button) findViewById(R.id.btn_kuaipan_account);

		btnOK = (Button) findViewById(R.id.btn_ok);
		btnExit = (Button) findViewById(R.id.btn_exit);

		// 监听器初始化
		listenerBtn = new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (v.equals(btnOK)) {
					Intent intent = new Intent(CloudDiskLoginActivity.this,
							BrowserActivity.class);
					startActivity(intent);

				} else if (v.equals(btnExit)) {
					finish();
				} else {
					Intent intent = new Intent(CloudDiskLoginActivity.this,
							AccountConfigActivity.class);
					int keyCode = 99;
					if (v.equals(btnGoogle)) {
						keyCode = Varibles.GOOGLE_REQUEST_CODE;
					} else if (v.equals(btnKanBox)) {
						keyCode = Varibles.KANBOX_REQUEST_CODE;
					} else if (v.equals(btnSnda)) {
						keyCode = Varibles.SNDA_REQUEST_CODE;
					} else if (v.equals(btnVDisk)) {
						keyCode = Varibles.VDISK_REQUEST_CODE;
					} else if (v.equals(btnKuaiPan)) {
						keyCode = Varibles.KUAIPAN_REQUEST_CODE;
					}
					intent.putExtra("keyCode", keyCode);
					startActivityForResult(intent, Varibles.REQUEST_CODE);
				}
			}
		};

		btnGoogle.setOnClickListener(listenerBtn);
		btnOK.setOnClickListener(listenerBtn);
		btnExit.setOnClickListener(listenerBtn);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == Varibles.REQUEST_CODE) {
			if (data != null) {
				Bundle bundle = data.getExtras();
				boolean result = bundle.getBoolean("result");
				switch (resultCode) {
				case Varibles.GOOGLE_REQUEST_CODE:
					if (result)
						Toast.makeText(CloudDiskLoginActivity.this,
								"Google Account setting success!",
								Toast.LENGTH_LONG).show();
					else
						Toast.makeText(CloudDiskLoginActivity.this,
								"Google Account setting failed!",
								Toast.LENGTH_SHORT).show();
					break;
				case Varibles.KANBOX_REQUEST_CODE:
					break;
				case Varibles.SNDA_REQUEST_CODE:
					break;
				case Varibles.VDISK_REQUEST_CODE:
					break;
				case Varibles.KUAIPAN_REQUEST_CODE:
					break;
				default:
					break;

				}
			} else {
				Toast.makeText(CloudDiskLoginActivity.this, "Setting failed!",
						Toast.LENGTH_LONG).show();
			}
		}
	}

}